<?php
//测试控制器类
class RegisterControl extends Control{
    public function __init()
    {
        if (isset($_SESSION['uid']) && isset($_SESSION['username'])) {
            go(U('Member/Index/index'));
        }
    }

    function index(){
        $this->display();
    }

    function register(){
    	if (IS_POST) {
    		$model = K('User');
    		if (!$model->create()) $this->error($model->error);    
            if(!$model->is_unique_username()) $this->error('用户名已存在!');		
    		$uid = $model->add_user();
            // p($uid);exit;
			//写入session信息
			session('username',Q('post.username'));
			session('uid',$uid);
			session('rid',Q('post.rid',0,'intval'));
			session('logintime',time());
			session('loginip',Ip::getClientIp());
			$this->success('注册成功',U('/Index/Index/index'));
    	}
    	$this->display();
    }
}
?>